package com.senlan.water.controller.project;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.senlan.water.common.result.BaseResult;
import com.senlan.water.dao.domain.MeetingRecords;
import com.senlan.water.dao.service.MeetingRecordsService;
import com.senlan.water.dto.project.MeetingRecordsAddDTO;
import com.senlan.water.dto.project.MeetingRecordsDTO;
import com.senlan.water.dto.project.MeetingRecordsEditDTO;
import com.senlan.water.dto.project.MeetingRecordsSearchDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/meeting")
@Slf4j
@SaCheckLogin
public class MeetingRecordController {

    @Resource
    private MeetingRecordsService meetingRecordsService;

    /**
     * 新增
     * @param addDTO
     * @return
     */
    @PostMapping("add")
    public BaseResult<Boolean> add(@RequestBody MeetingRecordsAddDTO addDTO) {
        return BaseResult.data(meetingRecordsService.addNew(addDTO));
    }

    /**
     * 编辑
     * @param editDTO
     * @return
     */
    @PostMapping("edit")
    public BaseResult<Boolean> edit(@RequestBody MeetingRecordsEditDTO editDTO){
        return BaseResult.data(meetingRecordsService.editById(editDTO));
    }

    /**
     * 分页查询
     * @param searchDTO
     * @return
     */
    @PostMapping("getPage")
    public BaseResult<Page<MeetingRecordsDTO>> getPage(@RequestBody MeetingRecordsSearchDTO searchDTO) {
        return BaseResult.data(meetingRecordsService.getPage(searchDTO));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("delete")
    public BaseResult<Boolean> delete(@RequestParam("id") Long id) {
        return BaseResult.data(meetingRecordsService.deleteById(id));
    }

    /**
     * 根据项目id查询会议记录
     * @param projectId
     * @return
     */
    @GetMapping("getByProjectId")
    public BaseResult<List<MeetingRecords>> getByProjectId(@RequestParam("projectId") Long projectId) {
        return BaseResult.data(meetingRecordsService.getByProjectId(projectId));
    }
}
